﻿using LxBasic;
using LxCore;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LxCFD
{
    class GraphPanelVM : BindableBase
    {
        public GraphPanelVM()
        {
            CreateGraph = new DelegateCommand(() =>
            {
                var g = GraphCenter.CreateGraph();
                SelGraph = g;
            });
            DeleteGraph = new DelegateCommand(() =>
            {
                int id = GraphCenter.Graphs.IndexOf(SelGraph);
                if (id < 0) return;
                GraphCenter.RemoveGraphAt(id);
            });
            OpenGraph = new DelegateCommand(openGraph);
        }
        public VisualCenter GraphCenter { get => LxSim.Sim.Visuals; }
        public ConditionCenter MeshSet { get => LxSim.Sim.Conditions; }

        private Graph _SelGraph;
        public Graph SelGraph
        {
            get { return _SelGraph; }
            set
            {
                _SelGraph = value; RaisePropertyChanged(nameof(SelGraph));
                ConditionCenter.CurrentGraph = value.ID;
                foreach (var zs in MeshSet.ZoneConds)
                {
                    zs.InnerCond.IsGraphSel = zs.InnerCond.IsGraphSel;
                }
                if (SelZoneSet != null)
                {
                    foreach (var bs in SelZoneSet.BoundConds)
                    {
                        bs.IsGraphSel = bs.IsGraphSel;
                    }
                }
            }
        }
        public DelegateCommand CreateGraph { get; set; }
        public DelegateCommand DeleteGraph { get; set; }
        public DelegateCommand OpenGraph { get; set; }
        public void openGraph()
        {
            if (SelGraph == null)
            {
                LxLog.Warn("未选中");
                return;
            }
            GraphDrawer gd = new GraphDrawer(SelGraph);
            gd.CreateGraph();
            GraphDisplay.DisplayGraph(gd.ModelVisual ,gd.ColorRange);
        }

        private MeshGraphTypes[] _MeshGraphTypes = Enum.GetValues<MeshGraphTypes>();
        public MeshGraphTypes[] MeshGraphTypes
        {
            get => _MeshGraphTypes;
            set { _MeshGraphTypes = value; RaisePropertyChanged(nameof(MeshGraphTypes)); }
        }
        private GraphTypes[] _GraphTypes = Enum.GetValues<GraphTypes>();
        public GraphTypes[] GraphTypes
        {
            get => _GraphTypes;
            set { _GraphTypes = value; RaisePropertyChanged(nameof(GraphTypes)); }
        }
        private ScalarFieldTypes[] _ScalarFieldTypes = Enum.GetValues<ScalarFieldTypes>();
        public ScalarFieldTypes[] ScalarFieldTypes
        {
            get => _ScalarFieldTypes;
            set { _ScalarFieldTypes = value; RaisePropertyChanged(nameof(ScalarFieldTypes)); }
        }
        private VectorFieldTypes[] _VectorFieldTypes = new VectorFieldTypes[] { LxCore.VectorFieldTypes.Velocity };
        public VectorFieldTypes[] VectorFieldTypes
        {
            get => _VectorFieldTypes;
            set { _VectorFieldTypes = value; RaisePropertyChanged(nameof(VectorFieldTypes)); }
        }

        private ZoneCond _SelZoneSet;
        public ZoneCond SelZoneSet
        {
            get { return _SelZoneSet; }
            set { _SelZoneSet = value; RaisePropertyChanged(nameof(SelZoneSet)); }
        }
        private BoundCond _SelBoundSet;
        public BoundCond SelBoundSet
        {
            get { return _SelBoundSet; }
            set { _SelBoundSet = value; RaisePropertyChanged(nameof(SelBoundSet)); }
        }
    }
}
